package com.pd.backend.service.impl;

import com.pd.backend.entity.PdTruckDriver;
import com.pd.backend.dao.PdTruckDriverDao;
import com.pd.backend.service.PdTruckDriverService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 司机表(PdTruckDriver)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:36
 */
@Service("pdTruckDriverService")
public class PdTruckDriverServiceImpl implements PdTruckDriverService {
    @Resource
    private PdTruckDriverDao pdTruckDriverDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdTruckDriver queryById(String id) {
        return this.pdTruckDriverDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdTruckDriver 筛选条件
     * @param pageRequest   分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdTruckDriver> queryByPage(PdTruckDriver pdTruckDriver, PageRequest pageRequest) {
        long total = this.pdTruckDriverDao.count(pdTruckDriver);
        return new PageImpl<>(this.pdTruckDriverDao.queryAllByLimit(pdTruckDriver, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdTruckDriver 实例对象
     * @return 实例对象
     */
    @Override
    public PdTruckDriver insert(PdTruckDriver pdTruckDriver) {
        this.pdTruckDriverDao.insert(pdTruckDriver);
        return pdTruckDriver;
    }

    /**
     * 修改数据
     *
     * @param pdTruckDriver 实例对象
     * @return 实例对象
     */
    @Override
    public PdTruckDriver update(PdTruckDriver pdTruckDriver) {
        this.pdTruckDriverDao.update(pdTruckDriver);
        return this.queryById(pdTruckDriver.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdTruckDriverDao.deleteById(id) > 0;
    }
}
